<template>
  <div class="flex alcenter jscenter vh100 login-main">
    <div class="bgpart radius4 plr60 ptb40 mb50 w25 mwidth">
      <div slot="title" class="tc ft20 color-b0b8db">{{ $t('Welcome to log in') }}</div>
      <div class="mt40">
        <div class="bdbea2 flex alcenter bold">
          <div class="pb10 mr20 pointer ft14 active2px">{{ $t('E-mail login') }}</div>
        </div>
      </div>
      <a-form-model ref="ruleForm" :model="form" :rules="rules" class="mt20">
        <a-form-model-item prop="email">
          <a-input
            v-model="form.email"
            class="flex1 nwhite ft14"
            :placeholder="$t('Please enter your email')"
          />
        </a-form-model-item>
        <a-form-model-item prop="password">
          <a-input-password
            v-model="form.password"
            class="flex1 nwhite ft14"
            :placeholder="$t('Please enter your password')"
          />
        </a-form-model-item>
        <div class="flex between alcenter mt10">
          <a-checkbox v-model="rememberMe">{{ $t('Remember password') }}</a-checkbox>
          <a class="blue ft16" href="#" @click="routerHandler('forgetPassword')">
            {{ $t('forgot password') }}？
          </a>
        </div>
        <a-form-model-item>
          <a-button
            :loading="loading"
            class="login-button text-color w100 mt40"
            size="large"
            type="primary"
            @click="onSubmit"
          >
            {{ $t('Login') }}
          </a-button>
        </a-form-model-item>
        <div class="mt10 tc ft16">
          {{ $t('Don’t have an account') }}
          <a class="color-primary" href="#" @click="routerHandler('/register')">
            {{ $t('Sign up') }}
          </a>
        </div>
      </a-form-model>
    </div>
  </div>
</template>
<script>
// import { Login } from "@/api/sys"
import { mapActions } from 'vuex'
import storage from 'store'
import { ACCESS_REMEMBER } from '@/utils/constants'

export default {
  data() {
    return {
      form: {
        email: '',
        password: ''
      },
      loading: false,
      rules: {
        email: [{ required: true, message: this.$t('Plaease input your email') }],
        password: [{ required: true, message: this.$t('Plaease input your password') }]
      },
      rememberMe: false
    }
  },
  mounted() {
    if (storage.get(ACCESS_REMEMBER)) {
      this.form = storage.get(ACCESS_REMEMBER) || { email: '', password: '' }
    } else {
      this.form = { email: '', password: '' }
    }
  },
  methods: {
    ...mapActions(['Login']),
    onSubmit() {
      console.log('submit!', this, this.form)
      this.$refs.ruleForm.validate((valid) => {
        // console.log(valid, "jiangege1993@gmail.com");
        if (valid) {
          if (this.rememberMe) {
            storage.set(ACCESS_REMEMBER, this.form)
          }
          this.loading = true
          this.Login(this.form)
            .then(() => {
              this.loading = false
              this.$notification.success({
                message: this.$t('提示'),
                description: this.$t('Login Successfully')
              })
              this.$router.replace({ path: '/' })
            })
            .catch(() => {
              // console.log(err, "jiangege1993@gmail.com");
              this.loading = false
            })
        }
      })
    },
    routerHandler(path) {
      this.$router.push({ path })
    }
  }
}
</script>
<style lang="scss" scoped>
.mwidth {
  min-width: 440px;
}

.color-b0b8db {
  color: #b0b8db;
}

// .login-main{
:deep.ant-input,
:deep.ant-input-password {
  .ant-input {
    height: 50px;
    background-color: transparent;
    color: white;
    // border: 1px solid #273344;
    // &:focus, &:hover{
    //   background-color: transparent;
    // }
  }

  .ant-input-password-icon {
    color: white;
  }
}

// :deep.has-error .ant-input, :deep.has-error .ant-input-password .ant-input{
//   &:focus, &:hover{
//     background-color: #f5222d;
//   }
// }
// }
</style>
